@extends("admin.layout.layout")
@section("content")
        <div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form layui-form-pane">
                    <input type="hidden" name="roleid" value="{{$role->id}}">
                    <div class="layui-form-item">
                        <label for="L_role_name" class="layui-form-label">
                            <span class="x-red">*</span>角色名称</label>
                        <div class="layui-input-inline">
                            <input type="text" id="L_role_name" name="role_name" value="{{$role->role_name}}" required="" autocomplete="off" class="layui-input"></div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">
                            拥有权限
                        </label>
                        <table  class="layui-table layui-input-block">
                            <tbody>
                            <tr>
                                <td>
                                    <div class="layui-input-block">
                                        @foreach($permission as $v)
                                            <input name="perid" @if(in_array($v->id,$own_perid)) checked @endif lay-skin="primary" type="checkbox" title="{{$v->per_name}}" value="{{$v->id}}">
                                        @endforeach
                                    </div>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                    <div class="layui-form-item">
                        <button class="layui-btn" lay-filter="update" lay-submit="">修改</button>
                    </div>
                </form>
            </div>
        </div>
        <script>layui.use(['form', 'layer'],
            function() {
                $ = layui.jquery;
                var form = layui.form,
                layer = layui.layer;
                //监听提交
                form.on('submit(update)',
                function(data) {
                    var perid=[];
                    $("input[name='perid']:checked").each(function(i){
                        perid[i] = $(this).val();
                    });
                    $.ajax({
                        url: '/admin/role/'+data.field.roleid,
                        type: 'PUT',
                        data:{
                            '_token':'{{csrf_token()}}'
                            ,'id':data.field.roleid
                            ,'role_name':data.field.role_name
                            ,'perid':perid
                        },
                        dataType:'json',
                        success: function(res) {
                            if(res.status == 0){
                                //发异步，把数据提交给php
                                layer.alert(res.message, {
                                        icon: 6
                                    },
                                    function() {
                                        //关闭当前frame
                                        xadmin.close();
                                        // 可以对父窗口进行刷新
                                        xadmin.father_reload();
                                    });
                            }else {
                                layer.msg(res.data[0]);
                            }
                        }
                    });
                    return false;
                });

            });</script>
@endsection